package com.ljh.controller;


import com.ljh.common.JsonData;
import com.ljh.pojo.Billdefail;
import com.ljh.pojo.Billtable;
import com.ljh.pojo.Menutable;
import com.ljh.pojo.OutTable;
import com.ljh.service.MENUTABLEervice;
import com.ljh.service.OUTTABLEervice;
import com.ljh.vo.BillDefaiVo;
import com.ljh.vo.MenutableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 刘剑鸿
 * @since 2021-11-02
 */
@Controller
@RequestMapping("/menutable")
public class MenutableController {

    @Autowired
    private MENUTABLEervice menutablEervice;
    @Autowired
    private OUTTABLEervice outtablEervice;
    @RequestMapping("ToOrder")
    public String ToOrder(){
        return "OrderDishes/order";
    }
    @RequestMapping("Todaohang")
    public String Todaohang(){
        return "fronydesk/fronydesk";
    }
    @RequestMapping("ToIndex")
    public String ToIndex(){
        return "redirect:/user/index";
    }

    @RequestMapping("loadmenu")
    @ResponseBody
    public JsonData loadmenu(MenutableVo menutableVo){
        return menutablEervice.menuAll(menutableVo);
    }
    @RequestMapping("ToaddBill")
    public String addBill(BillDefaiVo billDefaiVo,Model model){
        List<OutTable> Open = outtablEervice.selectOpen();
        model.addAttribute("Open",Open);
        System.out.println("aa"+billDefaiVo);
       List<Menutable> men =  menutablEervice.ToBill(billDefaiVo);

       model.addAttribute("Menu",men);
        return "OrderDishes/toBill";
    }

    @RequestMapping("AddMenu")
    @ResponseBody
    public JsonData AddMenuBill(BillDefaiVo billDefaiVo, Billtable billtable){
        //System.out.println("用户Id"+billtable.getId());//可获取ID  和  变化 数量
        //数组ID 全部查找出来
       // System.out.println(billDefaiVo.getOutTableid());
         menutablEervice.OnBill(billDefaiVo,billtable);
        //获取集合，进行批量修改
        return JsonData.success("下单成功");

    }
}

